﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;


namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UReturnVisitList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看,Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "UReturnVisitList";
            }
        }
        #region 属性 (查询条件)


        
        protected string CustomerName
        {
            get
            {
                return GetRequestValue<string>("CustomerName", "");

            }
        }
        protected string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber", "");

            }
        }

        protected string AgentName
        {
            get
            {
                return GetRequestValue<string>("AgentName", "");

            }
        }
       
        protected string AgentAddress
        {
            get
            {
                return GetRequestValue<string>("AgentAddress", "");

            }
        }

        protected bool ShowTimeInput
        {
            get
            {
                return GetRequestValue<bool>("ShowTimeInput", true);
            }
        }
        protected string CreateDateFrom
        {
            get
            {
                return ShowTimeInput ? DateTime.Now.ToString("yyyy-MM-01") : GetRequestValue<string>("CreateDateFrom", "");


            }
        }

        protected string CreateDateTo
        {
            get
            {
                string _temp = ShowTimeInput ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : GetRequestValue<string>("CreateDateTo", "");

                return CreateDateFrom.IsEmptyOrNull() ? "" : _temp.IsEmptyOrNull() ? Convert.ToDateTime(CreateDateFrom).AddDays(1).ToString("yyyy-MM-dd") : _temp;

               
            }
        }
        protected override string orderField
        {
            get
            {
                return GetRequestValue<string>("orderfield", "CreateDate");
            }
        }

        protected override string orderDirection
        {
            get
            {
                return GetRequestValue<string>("orderDirection", "DESC");
            }
        }
        #endregion

        protected string GetSQLWhere()
        {

            string wheresql = "";
            string sqlcommonFiled = "";
            if (!string.IsNullOrEmpty(SerialNumber))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("SerialNumber", QueryOperatorsEnum.包含, SerialNumber);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (!string.IsNullOrEmpty(CustomerName))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("CustomerName", QueryOperatorsEnum.包含, CustomerName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (!string.IsNullOrEmpty(AgentName))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("AgentName", QueryOperatorsEnum.包含, AgentName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }




            if (CreateDateFrom != "")
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("CreateDate", QueryOperatorsEnum.范围, CreateDateFrom + "|" + CreateDateTo);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
           
            return wheresql;
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
            AddLog(Permission.查看);
        }

        protected void DataBind()
        {
            //  string wheresql = QueryOperatorsEnumHelper.ConvertCommonOperator(CommonFiled, QueryOperatorsEnum.包含, CommonValue);

            this.rpMenu.DataSource = UReturn500VisitController.GetPagination(GetSQLWhere(), pageNum, numPerPage, SQLSort, ref TotalCount);
            this.rpMenu.DataBind();
        }

        protected string Get有OR没有(object o)
        {
            if (o == DBNull.Value)
                return "";
            if (Convert.ToInt16(o) == 0)
                return "没有";
            if (Convert.ToInt16(o) == 1)
                return "有";
            return "";
        }
        protected string Get满意(object o)
        {
            if (o == DBNull.Value)
                return "";
            if (Convert.ToInt16(o) == 0)
                return "不满意";
            if (Convert.ToInt16(o) == 1)
                return "满意";
            return "";
        }
        protected string Get工作态度(object o)
        {
            if (o == DBNull.Value)
                return "";
            short xx = Convert.ToInt16(o);
            if (xx == 4)
                return "非常满意";
            if (xx == 3)
                return "满意";
            if (xx == 2)
                return "一般";
            if (xx == 1)
                return "不满意";
            if (xx == 0)
                return "恶劣";
            return "";
        }
        protected string Get主动联系(object o)
        {
            if (o == DBNull.Value)
                return "";
            if (Convert.ToInt16(o) == 0)
                return "打电话";
            if (Convert.ToInt16(o) == 1)
                return "主动联系";
            return "";
        }
        protected string Get配件价格合理(object o)
        {
            if (o == DBNull.Value)
                return "";
            short xx = Convert.ToInt16(o);
            if (xx == 4)
                return "不能接受";
            if (xx == 3)
                return "价格偏贵";
            if (xx == 2)
                return "能接受";
            if (xx == 1)
                return "价格一般";
            return "";
        }
    }
}